package com.gmall.coupon.controller;

import com.gmall.common.result.Result;
import com.gmall.coupon.service.CouponUserService;
import com.gmall.model.activity.dto.SkuCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/coupon/")
public class CouponApiController {

    @Autowired
    CouponUserService couponUserService;
    /**
     * 获取该SKUID 可用的优惠卷
     * @param skuId
     * @return
     */
    @GetMapping("getCouponListBySkuId/{skuId}/{skuNum}")
    public Result<List<SkuCoupon>> getCouponListBySkuId(
            @PathVariable Long skuId,
            @PathVariable Integer skuNum,
            @RequestHeader Long userId){

        return couponUserService.getCouponListBySkuId(userId, skuId,skuNum);
    }

    @GetMapping("getCheckedCouponBySkuId/{skuId}/{skuNum}")
    public Result<SkuCoupon> getCheckedCouponBySkuId(
            @PathVariable Long skuId,
            @PathVariable Integer skuNum,
            @RequestHeader Long userId){

        return couponUserService.getCheckedCouponBySkuId(userId, skuId,skuNum);
    }

    @GetMapping("getCouponInfo/{couponId}")
    public Result<String> getCouponInfo(@PathVariable Long couponId,
                                        @RequestHeader Long userId){
        return couponUserService.getCouponInfo(couponId,userId);
    }

    @GetMapping("useCoupon/{couponId}/{userId}/{orderId}")
    public Result<String> useCoupon(@PathVariable Long couponId,
                                    @PathVariable Long userId,
                                    @PathVariable Long orderId){
        return couponUserService.useCoupon(couponId,userId,orderId);
    }

    @GetMapping("unUseCoupon/{orderId}")
    public Result<String> unUseCoupon(@PathVariable Long orderId){
        return couponUserService.unUseCoupon(orderId);
    }
}
